package cn.wangsy.zhidao.p20170113;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

	public static void main(String[] args) {

		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		
		//昨天
		Calendar calendar = Calendar.getInstance();
		calendar.add(Calendar.DATE, -1);
		System.out.println(dateFormat.format(calendar.getTime()));
		
		//本月第一天
		calendar.clear();
		calendar.setTime(new Date());
		calendar.set(Calendar.DATE, 1);
		System.out.println(dateFormat.format(calendar.getTime()));
		
		//上周一
		calendar.clear();
		calendar.setTime(new Date());
		int day_of_week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
		if (day_of_week == 0) {
			day_of_week = 7;
		}
		calendar.add(Calendar.DATE, -day_of_week + 1);
		System.out.println(dateFormat.format(calendar.getTime()));
	}

}
